<?php
class Ajax extends MbNews_Controller {

    function __construct() {
        parent::__construct();
    }

	public function repost(){
		if(!isLogin()){
			echo response(401,'msg','请登录再试！');
			return;
		}

		$content = "转发微博";
		$type = 0;
		$sid = 0;
		if(!isset($_POST['wid'])){
			echo response(402,'msg','没有微博ID');
			return;
		}else{
			$sid = $_POST['wid'];
		}

		if(isset($_POST['text'])){
			$content = urldecode($_POST['text']);
		}
		if(isset($_POST['type'])){
			$type = $_POST['type'];
		}
        $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
		$wb = $c->repost($sid,$content,$type);
		echo response(200,'msg','发送成功',array('sid'=>$wb['id']));
	}
	public function comment(){
		if(!isLogin()){
			echo response(401,'msg','请登录再试！');
			return;
		}

		$content = "转发微博";
		$type = 0;
		$sid = 0;
		if(!isset($_POST['wid'])){
			echo response(402,'msg','没有微博ID');
			return;
		}else{
			$sid = $_POST['wid'];
		}

		if(isset($_POST['text'])){
			$content = urldecode($_POST['text']);
		}
		if(isset($_POST['type'])){
			$type = $_POST['type'];
		}
        $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
		$wb = $c->send_comment($sid,$content,$type);
		echo response(200,'msg','发送成功',array('sid'=>$wb['id']));
	}
	public function favorites(){
		if(!isLogin()){
			echo response(401,'msg','请登录再试！');
			return;
		}	
		$sid = 0;
		if(!isset($_POST['wid'])){
			echo response(402,'msg','没有微博ID');
			return;
		}else{
			$sid = $_POST['wid'];
		}
        $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
		$wb = $c->add_to_favorites($sid);
		if(isset($wb['error_code'])){
			echo response($wb['error_code'],'msg',$wb['error'],array('sid'=>0));	
		}else{
			echo response(200,'msg','收藏成功',array('sid'=>$wb['status']['id']));
		}
	}
}
?>